<template>
	<view>
		<!-- <image class="bg-img" src="/static/img/splash.png"></image>
		<view class="in-btn" @click="enter">立即体验</view> -->
		<view  class="content" v-if="showUpdate">
			<view class="dialog">
				<image class="dialog-img" src="/static/img/sys_update_bg.png"></image>
				<view class="dialog-title">{{title}}</view>
				<view class="dialog-content">
					<text class="dialog-txt">{{content}}</text>
				</view>
				<view class="dialog-btn" @click="quit">我知道了</view>
			</view>
		</view>

	</view>
</template>

<script>
	import {quitApp} from '@/utils/page';
    import mixins from '@/mixins/index';
    import {mapState, mapGetters, mapMutations, mapActions} from 'vuex';
    import {authCheck} from '@/utils/page'
    import {isEmpty, resetState} from '@/utils/index';

	import msgService from '@/services/msg';

	const service = new msgService(false,false);

    export default {
        mixins:[mixins],
        props:{

        },
        data() {
            return {
				tag:'router',
				webUrl:'',
				routerUrl:'/pages/search/search',
				showUpdate:false,
				title:'',
				content:'',
				clicked:false,
            }
        },
		onLoad(){
			this.loadNotice();
            const $this = this;
            uni.getSystemInfo({
                success: function (res) {
                    const {windowWidth,windowHeight,brand,model,statusBarHeight} = res;
                    $this.updateSystemInfo({statusBarHeight,windowWidth,windowHeight,brand,model})
                }
            });
			//所有安装包升级后必须重新登录
			const clearFlag = uni.getStorageSync('clearFlag');
			if(isEmpty(clearFlag)||clearFlag=='0'){//未清除过数据
				this.logout();
				uni.setStorageSync('clearFlag', '1');
			}
			//this.loadNotice();

        },
        onReady(){
            /**
             * 启动页广告 使用文档（滑稽）
             * 1. 引入组件并注册
             * 		import mixAdvert from '@/components/mix-advert/vue/mix-advert';
             *      components: {mixAdvert},
             <!-- #ifndef MP -->
             <mix-advert
             ref="mixAdvert"
             :timedown="8"
             imageUrl="/static/advert.jpg"
             :url="advertNavUrl"
             ></mix-advert>
             <!-- #endif -->
             * 	2. 调用组件的initAdvert()方法进行初始化
             *
             *  初始化的时机应该是在splash关闭时，否则会造成在app端广告显示了数秒后首屏才渲染出来
             */
            //this.loadExecution();
            //this.$refs.mixAdvert.initAdvert();
             // #ifndef APP-PLUS
            //this.$refs.mixAdvert.initAdvert(this.adverteUrl);
            // #endif

        },
        computed:{

        },
        methods: {
            ...mapActions({
                updateVersionCode: 'settings/updateVersionCode',
                updateSystemInfo: 'settings/updateSystemInfo',
            }),
			...mapMutations({
			    logout: 'user/logout',
			}),
			quit(){
				quitApp();
			},
			//进入app
			enter(){
				// console.log('dianji');
				this.loadExecution();
			},
			//加载系统公告
			loadNotice(){
				service.notice().then(response=>{
					// console.log('公告：',JSON.stringify(response));
					if(response.success&&response.result.hasNotice){
						this.showUpdate = true;
						this.title = response.result.title;
						this.content = response.result.content;
					}else{
						this.loadExecution();
					}
				}).catch((reason)=>{
					// console.log('异常：',reason);
					this.loadExecution();
				});
			},
            tapCallback(tag,webUrl,routerUrl){
                // uni.navigateTo({
                //     url:'/pages/search/search'
                // })
				console.log("sinner tag",tag);
                console.log("sinner webUrl",webUrl);
                console.log("sinner routerUrl",routerUrl);
                if(isEmpty(routerUrl)||isEmpty(webUrl)){
                        return;
                }
 				if(tag == 'web')
				{
					// uni.navigateTo({
                    //     url: '/pages/web/web?src='+webUrl
					// });
				}else if(tag == 'router')
				{
                    uni.navigateTo({
						url:routerUrl
                    });
				}
            },
            loadExecution: function(){
				if(this.clicked){
					return;
				}
				this.clicked = true;
				// console.log('加载进入逻辑loadExecution');
                /**
                 * 获取本地存储中launchFlag的值
                 * 若存在，说明不是首次启动，直接进入首页；
                 * 若不存在，说明是首次启动，进入引导页；
                 */
                try {
                    // const value = uni.getStorageSync('launchFlag');
					const value = true;
                    if (value) {
                        if (value == true) {
                            authCheck({
                                exceptionCallback:()=>{
                                    console.log('userDataForLogin:',this.userDataForLogin);
                                    if(this.userDataForLogin.gesture!=undefined && this.userDataForLogin.useGesture){
                                        uni.redirectTo({
                                            url: '/pages/system/gestureLock/gestureLock'
                                        })
                                    }else{
                                        uni.redirectTo({
                                            url: '/pages/system/login/index'
                                        })
                                    }

                                },
                                callbackSuccess:()=>{
                                    uni.switchTab({
                                        url: '/pages/tabbar/home/index'
                                    });
                                }
                            })
                        } else {
                            uni.navigateTo({
                                url: '/pages/index/guide'
                            });
                        }
                    } else {
                        uni.setStorage({
                            key: 'launchFlag',
                            data: true,
                            success: function() {
                                console.log('存储launchFlag');
                                uni.navigateTo({
                                    url: '/pages/index/guide'
                                });
                            }
                        });
                    }
                } catch(e) {
                    // error
                    uni.setStorage({
                        key: 'launchFlag',
                        data: true,
                        success: function () {
                            console.log('error时存储launchFlag');
                        }
                    });
                    uni.navigateTo({ url: '/pages/index/guide' });
                }
                return;
            }
        }
    }
</script>
<style lang='scss' scoped>
	.content{
		margin: auto;
		position: fixed;
		width: 100%;
		height: 100%;
		background-color: rgba(0,0,0,0.4);
		/* z-index: 1000; */
	}
	.bg-img{
		position: fixed;
		width: 100%;
		height:100%;
		top: 0;
		left: 0;
		z-index: 0;
	}
	.in-btn{
		position: absolute;
		height: 60upx;
		line-height: 60upx;
		padding: 0 40upx;
		border-radius: 30upx;
		font-size: 32upx;
		color: #fff;
		border: 2upx solid #377cfd;
		z-index: 999;
		top: 80upx;
		right: 60upx;
		background-color: rgba(0,0,0,0.4);
	}
	.dialog{
		width: 260px;
		border-radius: 10px;
		text-align: center;
		padding: 0 20px 10px;
		position: fixed;
		top: 50%;
		right: 0;
		left: 50%;
		transform: translate(-50%,-50%);
		background-color: #fff;

		&-img{
			width: 320upx;
			height: 320upx;
			/* background:url('~@/static/img/sys_update_bg.png') no-repeat center center;
			background-size: 100% 100%; */
		}

		&-title{
			color: #2795fe;
			font-size: 32upx;
			font-weight: 600;

		}

		&-content{
			font-size: 28upx;
			color: #333333;
			padding: 20upx 0 30upx;
			text-align: left;
		}

		&-btn{
			width: 80%;
			height: 80upx;
			line-height: 80upx;
			margin: 0 auto;
			background-color: #2795fe;
			border-radius: 8upx;
			font-size: 28upx;
			color: #ffffff;
		}
	}
</style>
